// pages/teamDetails/teamDetails.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teamInfo:{},
    imgpath:'',
    teamId: '',
    team_member:[],
    httpPath: app.globalData.imagePath
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var _key = wx.getStorageSync("token");
    that.setData({
      teamId: options.teamid
    });
    wx.showLoading({
      title: '数据加载中'
    })
    //球队信息
    wx.request({
      url: app.globalData.httpsPath + '/team/show',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        team_id: options.teamid
      },
      //请求后台数据成功  
      success: function (res) {
        wx.hideLoading();
        that.setData({
          teamInfo: res.data.data,
          imgpath: app.globalData.imagePath + res.data.data.logo
        })
      }
    })
    //球队队员
    wx.request({
      url: app.globalData.httpsPath +'/team/users',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: _key,
        team_id: options.teamid
      },
      //请求后台数据成功  
      success: function (res) {
        var team_member = res.data.data;
        that.setData({
          team_member: team_member
        })
      }
    })
  },

  //申请加入
  applicationClick:function(){
    var that = this;
    var _teamid = that.data.teamId;
    var _token = wx.getStorageSync("token");
    console.info(_teamid);
    wx.request({
      url: app.globalData.httpsPath + '/team/apply-join',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: _token,
        team_id: _teamid,
      },
      //请求后台数据成功  
      success: function (res) {
        wx.showToast({
          title: '申请成功',
          icon: 'succes',
          duration: 3000,
          mask: true
        })
      }
    })
  }
  
})